<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style type="text/css">
#add_inventory_location_info .box label span {
	display: inline-block;
	width: 74px;
	text-align: right;
}

#add_inventory_location_info .box label {
	margin-left: 20px;
}

#add_inventory_location_info .formBox {
	padding: 0;
	position: relative;
}

#add_inventory_location_info .formBox>div {
	padding: 20px;
}

#add_inventory_location_info .updateBox label span {
	width: 96px;
}
</style>
<div class="modal fade" id="add_inventory_location_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 360px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新增库位</h4>
			</div>
			<form id="add_inventory_location_form" class="form">
				<input type="hidden" name="firstid" id="firstid">
				<div class="box modal-body">
					<p>
						<label>库位编码</label>
						<input type="text" class="form-control" id="inventorylocationcode" readonly placeholder="自动生成">
					</p>
					<p id="chooseWarehouse">
						<label>所属仓库</label>
						<select name="warehouseManagementID" class="form-control select">
							<c:forEach items="${warehoseList }" var="warehouse">
								<option value="${warehouse.warehousemanagementid }">${warehouse.warehousename }</option>
							</c:forEach>
						</select>
					</p>
					<p>
						<label>库位名称</label>
						<input type="text" class="form-control" name="inventorylocationname"></input>
					</p>
					<p>
						<label>库位备注</label>
						<input type="text" class="form-control" name="description"></input>
					</p>
				</div>
			</form>
			<div class="red" id="add_inventory_location_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn1" onclick="saveAddInventoryLocation();">保存</button>
				<button type="button" class="btn btn2" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script>

function addInventoryLocation(id){
	if(id==0){
		$("#add_inventory_location_info #chooseWarehouse").css("display","block");
	}else{
		$("#add_inventory_location_info #chooseWarehouse").css("display","none");
	}
	$('#add_inventory_location_info :text').val("");
	$("#add_inventory_location_info #firstid").val(id);
	$('#add_inventory_location_info').modal('show');
}

function saveAddInventoryLocation(){
	
	if(!validateAddFormthere()) return ;//校验
	$.ajax({
		url:"<%=basePath %>inventorylocation/add.do",
		type:"post",
		async : false,
		dataType:"json",
		data : $("#add_inventory_location_form").serialize(),
		success:function(data){
			if(data.result=="success"){
				$("#add_inventory_location_msg").html("");
				$('#add_inventory_location_info :text').val("");
				$("#add_inventory_location_info select").val("");
				$("#add_inventory_location_info #firstid").val("");
				$('#add_inventory_location_info').modal('hide');
				location.href=location.href;
			}else{
				$("#add_inventory_location_msg").html("新增物品分类失败：",data.error);
			}
		},
		error :function(){
			$("#add_inventory_location_msg").html("新增物品分类失败！")
		}
	});
}

//仓库管理校验
function validateAddFormthere(){
	
 	if(!validateSelect("所属仓库","#add_inventory_location_form [name='warehouseManagementID']",30,false)){
		return false;
	}  
	
	if(!validateString("库位名称","#add_inventory_location_form [name='inventorylocationname']",30,false)){
		return false;
	} 
	
	if(!validateString("库位备注","#add_inventory_location_form [name='description']",190,false)){
		return false;
	} 
	return true;
}





</script>